package com.yumao.animatordemo;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.Button;

public class Main3Activity extends AppCompatActivity {

    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        button = (Button) findViewById(R.id.button);
    }

    public void onClick(View view) {
        ValueAnimator animator = ValueAnimator.ofInt(0, 10);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                Integer a = (Integer) animation.getAnimatedValue();
                button.setText(a.toString());
            }
        });
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                button.setClickable(true);
            }

            @Override
            public void onAnimationStart(Animator animation) {
                button.setClickable(false);
            }
        });
        animator.setDuration(8000);
        animator.setInterpolator(new AccelerateDecelerateInterpolator());
        animator.start();
    }
}
